
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.rmi.RemoteException;
import java.util.List;

public class InteractingBoard extends WhiteBoard implements MouseMotionListener, MouseListener {

	

	/**
	 * 
	 */
	private static final long serialVersionUID = 5173201691083038689L;
	
	WhiteBoardClient client;
	Point lastPoint;
	
/*
 * Problem solved!
 */

	public InteractingBoard(WhiteBoardClient whiteBoardClient) {
		super(whiteBoardClient.getModel(), "White Board Client");
		client = whiteBoardClient;
		addMouseListener(this);
		addMouseMotionListener(this);
		// TODO Auto-generated constructor stub
	}
	
//	public void paint(Graphics g){
//		g.clearRect(0, 0, getWidth(), getHeight());
//
//		List<Line> lst = model.getLines();
//		for (int i = 0; i < lst.size(); i++) {
//			Line l = lst.get(i);
//			Color c = l.color;
//			g.setColor(c);
//			g.drawLine(l.start.x, l.start.y, l.end.x, l.end.y);
//		}
//		
//		g.drawString("ASDFASDFASDFASDFASDFSADFASDFASDF", 50, 50);
//	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		lastPoint = arg0.getPoint();
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		updateClient(arg0);
		lastPoint = arg0.getPoint();

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		updateClient(arg0);
		lastPoint = null;

	}

	private void updateClient(MouseEvent e) {

			client.sendLine(lastPoint, e.getPoint());
//			client.getServer().line(client.getName(), lastPoint, e.getPoint());
			client.getBoard().repaint();

	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
